package com.demo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.demo.pojo.User;
import com.demo.service.dto.UserDto;
import com.demo.service.vo.MyConverterUtils;

import java.util.Date;
import java.util.List;

public class ABSDFDSA {
    public static void main(String[] args) {

//        System.out.println(getWeekStartEnd(DateUtil.lastWeek()));

//        System.out.println(getMothStartEnd(DateUtil.lastMonth()));

        UserDto test = MyConverterUtils.INSTANCE.toUserDto(User.builder().name("test").age(12).id(1L).birthDay(new Date()).build());
        System.out.println(test);
    }

    public static List<Date> getMothStartEnd(DateTime date) {
        return CollUtil.newArrayList(DateUtil.beginOfDay(DateUtil.offsetDay(date , -(date.dayOfMonth() - 1))),
                DateUtil.endOfDay(DateUtil.offsetDay(date, DateUtil.lengthOfMonth(date.month() + 1, DateUtil.isLeapYear(date.year())) - date.dayOfMonth()))
        );
    }

    /**
     * 获取当前一个周的第一天和最后一天
     * @return list.get(0) 当周第一天， list.get(1) 当周最后一天
     */
    public static List<Date> getWeekStartEnd(DateTime dateTime) {

        return CollUtil.newArrayList(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -(dateTime.dayOfWeek() - 1))),
                DateUtil.endOfDay(DateUtil.offsetDay(dateTime, (7 - dateTime.dayOfWeek())))
        );
    }
}
